home *** CD-ROM | disk | FTP | other *** search
- Path: inforamp.net!ts26-11
- From: rmorin@inforamp.net (Randy Charles Morin)
- Newsgroups: comp.lang.c++
- Subject: Coding Standards
- Date: Wed, 06 Mar 96 05:39:38 GMT
- Organization: MiddleWorld SoftWare
- Message-ID: <4hj8ek$elu@sam.inforamp.net>
- NNTP-Posting-Host: ts26-11.tor.inforamp.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- The company I just started a contract with gave me a set of C++ coding
- standards. I started reading and couldn't stop laughing. I can't reproduce
- them word-for-word, because that wouldn't be nice to the authors and might be
- considered a copyright violation or privacy violation, but I'll outline some
- of the points.
-
- -source files should have the extension .cc (not .cpp or .c).
- -header files should have the extension .hh (not .hpp or .h).
- -inline C++ functions should be in a file with the extension .icc (not
- in the primary header).
- -do not use the /* */ comment, except when commenting out entire
- sections of code. My understanding is that /* */ comments are ANSI comments,
- while // comments are not ANSI.
- -a class which can be instantiated with a "new" must have a copy
- constructor, a destructor and an assignment operator definition. This will
- extend the project another month.
- -never use #define instead or const. What if your concerned about the
- mix between code space and data space.
- -variable are to be declared with the smallest possible scope.
- void c::f()
- {
- {
- int b;
- {
- int a;
- a=b+c;
- b=a+d;
- }
- e=b+d;
- }
- f=e+4;
- }
- this type of optimization could take forever.
- -don't use explicit type conversions. In other words, don't program
- in windows. Explicit type conversion is necessary to convert GDI object
- handles.
- -don't use implicit type conversions implicitly, use them explicitly.
- Hello!
- -every case statement must be terminated with a break statement. What
- if you want to step through more then one case statement?
- case ENGINE_NOT_ACTIVE:
- start_engine();
- case ENGINE_ACTIVE_NOT_IN_DRIVE:
- shift_to_drive();
- case ENGINE_ACTIVE_IN DRIVE:
- press_accelerator();
- break;
- -don't use conditional compilation preprocessor directives. There
- goes cross-platform development.
- -optimize code only when you have a problem. So we can't optimize
- size in order to anticipate that code size will be a problem. First we have
- to experience the problem (most likely in the field).
- -access functions are to be inline. Inline access functions defeat
- the purpose of having access functions.
- -give protected accessors for all data members. What if we need to
- make the accessor public. Should we define one protected and one public.
- -++ and -- operations should be on a separate line.
- for (i=0; i<0;
- i++
- );
- Is that better?
- -don't allocate memory and expected someone else will delete it later.
- Can't use OWL, because control classes are automatically deleted for you.
-
- Agrivar
-